package com.atguigu.gulimall.seckill.controller;

import com.atguigu.common.utils.R;
import com.atguigu.gulimall.seckill.service.SeckillService;
import com.atguigu.gulimall.seckill.to.SecKillSkuRedisTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @description:
 * @author: BlueSky
 * @create: 2021-10-13 17:46
 **/

@RestController
public class SeckillController {

	@Autowired
	SeckillService seckillService;

	//返回当前时间可以参与的秒杀商品信息
	@GetMapping("/currentSeckillSkus")
	public R getCurrentSeckillSkus(){
		List<SecKillSkuRedisTo> vos	= seckillService.getCurrentSeckillSkus();
		return R.ok().setData(vos);
	}

	//获取秒杀预告信息
	@GetMapping("/sku/seckill/{skuId}")
	public R getSkuSeckillInfo(@PathVariable("skuId") Long skuId){

		SecKillSkuRedisTo to = seckillService.getSkuSecKillInfo(skuId);
		return R.ok().setData(to);
	}

	@GetMapping("/kill")
	public R secKill(@RequestParam("killId") String killId,
					 @RequestParam("key") String key,
					 @RequestParam("num") Integer num) throws InterruptedException {

		String orderSn = seckillService.kill(killId,key,num);
		//判断是否登录
		return null;
	}
}
